//
//  Registered.m
//  ahssc
//
//  Created by zuqiu on 17/3/27.
//  Copyright © 2017年 zuqiu. All rights reserved.
//

#import "Registered.h"
#import "NSString+Helper.h"
#import "UIHelper.h"
@interface Registered ()<UITextFieldDelegate>
@property (strong, nonatomic) IBOutletCollection(UITextField) NSArray *collects;

@end

@implementation Registered

#pragma mark UITextField代理方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == _collects[0]) {
        [_collects[1] becomeFirstResponder];
    } else if (textField == _collects[1]) {
        [_collects[2] becomeFirstResponder];
    } else {
        
        [self registeredBtn:nil];
    }
    
    return YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"注册";
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:127.3/255.0 green:185.1/255.0 blue:38.4/255.0 alpha:1.0]];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
}



- (IBAction)registeredBtn:(id)sender
{
    [self.view endEditing:YES];
    [self Registered];
}

- (void)Registered
{
    NSString *username = [[_collects[0] text] trimString];
    NSString *password = [_collects[1] text];
    NSString *aginPw   = [_collects[2] text];
    
     if (![username isEmptyString]) {
         [UIHelper showTipsWithText:@"用户名不能为空" inView:self.view];
     }else if(![password isEmptyString]){
         [UIHelper showTipsWithText:@"密码不能为空" inView:self.view];
     }else if(![aginPw isEmptyString]){
         [UIHelper showTipsWithText:@"确认密码不能为空" inView:self.view];
     }else if(![password isEqualToString:aginPw]){
         [UIHelper showTipsWithText:@"两次密码不一致" inView:self.view];
     }else{
         [UIHelper showTipsWithText:@"注册成功" inView:self.view];
         [username saveToNSDefaultsWithKey:@"username"];
         [password saveToNSDefaultsWithKey:@"password"];
         [self performSelector:@selector(delayMethod) withObject:nil afterDelay:1.5f];
     }
}

- (void)delayMethod
{
    [UIHelper showTipsWithText:@"注册信息已提交审核,审核时间为1～3天" inView:self.view];

//    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark ----------------view’s layout behavior--------------------
- (BOOL)prefersStatusBarHidden{
    return NO;
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

@end
